package com.example.project.controller.project;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.entity.TimeEntrie;
import com.example.project.enums.BusinessType;
import com.example.project.service.TimeEntrieService;
import com.example.project.utils.poi.ExcelUtil;

/**
 * 时间记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-17
 */
@Controller
@RequestMapping("/project/entrie")
public class TimeEntrieController extends BaseController {

	private String prefix = "pm/entrie";

	@Autowired
	private TimeEntrieService timeEntriesService;

	@RequiresPermissions("project:entrie:view")
	@GetMapping()
	public String entrie() {
		return prefix + "/entrie";
	}

	/**
	 * 查询时间记录列表
	 */
	@RequiresPermissions("project:entrie:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TimeEntrie timeEntries) {
		startPage();
		List<TimeEntrie> list = timeEntriesService.selectTimeEntriesList(timeEntries);
		return getDataTable(list);
	}

	/**
	 * 导出时间记录列表
	 */
	@RequiresPermissions("project:entrie:export")
	@Log(title = "时间记录", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(TimeEntrie timeEntries) {
		List<TimeEntrie> list = timeEntriesService.selectTimeEntriesList(timeEntries);
		ExcelUtil<TimeEntrie> util = new ExcelUtil<TimeEntrie>(TimeEntrie.class);
		return util.exportExcel(list, "时间记录数据");
	}

	/**
	 * 新增时间记录
	 */
	@RequiresPermissions("project:entrie:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存时间记录
	 */
	@RequiresPermissions("project:entrie:add")
	@Log(title = "时间记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TimeEntrie timeEntries) {
		return toAjax(timeEntriesService.insertTimeEntries(timeEntries));
	}

	/**
	 * 修改时间记录
	 */
	@RequiresPermissions("project:entrie:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		TimeEntrie timeEntries = timeEntriesService.selectTimeEntriesById(id);
		mmap.put("timeEntries", timeEntries);
		return prefix + "/edit";
	}

	/**
	 * 修改保存时间记录
	 */
	@RequiresPermissions("project:entrie:edit")
	@Log(title = "时间记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TimeEntrie timeEntries) {
		return toAjax(timeEntriesService.updateTimeEntries(timeEntries));
	}

	/**
	 * 删除时间记录
	 */
	@RequiresPermissions("project:entrie:remove")
	@Log(title = "时间记录", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(timeEntriesService.deleteTimeEntriesByIds(ids));
	}
}
